import java.net.*;
import java.io.*;

public class UDPClient{
    public static void main(String[] args){
        DatagramSocket aSocket=null;
        long sum=0;
        try{
            for(int i=0;i<1000;i++){
                aSocket=new DatagramSocket();
                
                byte[] m = "".getBytes();
                InetAddress aHost = InetAddress.getByName("127.0.0.1");
                int serverPort = 6789;
                DatagramPacket request = new DatagramPacket(m,"".length(),aHost,serverPort);

                long start = System.nanoTime();
                aSocket.send(request);
                byte[] buffer = new byte[1000];
                DatagramPacket reply = new DatagramPacket(buffer,buffer.length);
                aSocket.receive(reply);
                long end  = System.nanoTime();
                long diff = end - start;
                sum = sum + diff;
            }
        }catch(Exception e){
            System.out.println("error");
        }
        System.out.println(sum + " nanosecond");
    }
}
